//*******************************************************************       //
//IMPORTANT NOTICE                                                          //
//================                                                          //
//Copyright Mentor Graphics Corporation 1996 - 1999.  All rights reserved.  //
//This file and associated deliverables are the trade secrets,              //
//confidential information and copyrighted works of Mentor Graphics         //
//Corporation and its licensors and are subject to your license agreement   //
//with Mentor Graphics Corporation.                                         //
//                                                                          //
//Use of these deliverables for the purpose of making silicon from an IC    //
//design is limited to the terms and conditions of your license agreement   //
//with Mentor Graphics If you have further questions please contact Mentor  //
//Graphics Customer Support.                                                //
//                                                                          //
//This Mentor Graphics core (m8051w v2002.080) was extracted on             //
//workstation hostid 8316cbec Inventra                                      //
// 8-bit up counter for M8051W/EW
// 
// $Log: m3s016dy.v,v $
// Revision 1.5  2001/11/20
// First checkin of version 2 features and name change
//
// Revision 1.2  2001/10/31
// First parsable verilog for EW
//
// Revision 1.1.1.1  2001/07/17
// Re-imported E-Warp from Farnham filesystem
//
// Revision 1.4  2000/10/24
// Multiplier rewritten to improve power consumption.
// Code changes for Leonardo (ECN01372).
// Code changes for formal verification tools (ECN01410).
// MOVX @Ri page address controllable from PORT2I if I/O ports ommitted (ECN01387).
//
// Revision 1.3  2000/02/05
// Name change repercussions
//
// Revision 1.2  1999/11/30
// More debug changes.
//
// Revision 1.1.1.1  1999/10/28
// "initialization and source check-in for m8051e"
//
// Revision 1.1  1999/10/22
// Initial revision
//
////////////////////////////////////////////////////////////////////////////////

module m3s016dy (CARRY_OUT, COUNT, MODE0, LOAD, CARRY_IN, COUNT_EN, DATA_IN,
//*******************************************************************       //
//IMPORTANT NOTICE                                                          //
//================                                                          //
//Copyright Mentor Graphics Corporation 1996 - 1999.  All rights reserved.  //
//This file and associated deliverables are the trade secrets,              //
//confidential information and copyrighted works of Mentor Graphics         //
//Corporation and its licensors and are subject to your license agreement   //
//with Mentor Graphics Corporation.                                         //
//                                                                          //
//Use of these deliverables for the purpose of making silicon from an IC    //
//design is limited to the terms and conditions of your license agreement   //
//with Mentor Graphics If you have further questions please contact Mentor  //
//Graphics Customer Support.                                                //
//                                                                          //
//This Mentor Graphics core (m8051w v2002.080) was extracted on             //
//workstation hostid 8316cbec Inventra                                      //
                 INT_RESET, PCLK);

  output       CARRY_OUT;		
  output [7:0] COUNT;		
  input        MODE0;		
  input        LOAD;		
  input        CARRY_IN;		
  input        COUNT_EN;		
  input  [7:0] DATA_IN;
  input        INT_RESET;
  input        PCLK;		

  reg    [7:0] COUNT;                               
  wire         C4;                                     
  wire         CARRY_OUT;                                     

  // Loadable synchronous 8-bit counter, with carry look ahead in 4-bit slices.

  always @ (posedge PCLK)
  begin: p_set_count
    if (INT_RESET)
      COUNT <= 8'h00;		
    else if (LOAD)
      COUNT <= DATA_IN;		
    else if (COUNT_EN)
    begin
      COUNT[0] <= COUNT[0] ^ CARRY_IN;		
      COUNT[1] <= COUNT[1] ^ (CARRY_IN && COUNT[0]);		
      COUNT[2] <= COUNT[2] ^ (CARRY_IN && COUNT[0] && COUNT[1]);		
      COUNT[3] <= COUNT[3] ^ (CARRY_IN && COUNT[0] && COUNT[1] && COUNT[2]);

      COUNT[4] <= COUNT[4] ^ C4;		
      COUNT[5] <= COUNT[5] ^ (C4 && COUNT[4]);		
      COUNT[6] <= COUNT[6] ^ (C4 && COUNT[4] && COUNT[5]);		
      COUNT[7] <= COUNT[7] ^ (C4 && COUNT[4] && COUNT[5] && COUNT[6]);
    end
  end		

  // Generate counter carry out for five or eight bit modes with
  // combinatorial dependence on the counter carry input.

  assign C4        = CARRY_IN && (&COUNT[3:0]);
  assign CARRY_OUT = CARRY_IN && (&COUNT[4:0]) && (MODE0 || &COUNT[7:5]);

endmodule
